<template>
	<view>
		<nav-header title="" :show-right="false">
		</nav-header>

		<view class="user-info">
			<view class="head">
				<!-- <head-image :name="group.nickName" :url="group.headImage" :size="100"></head-image> -->
				<image class="avatar-image" v-if="group.headImage" :src="group.headImage" lazy-load="true"
					mode="aspectFill" />
				<image class="avatar-image" v-else :src="getResource('/icon/qun-avatar-default.svg')" lazy-load="true"
					mode="aspectFill" />
				<view class="right">
					<text>{{ group.name }}</text>
					<view class="num-item">
						<text>群号：{{ group.groupNumber }}</text>
						<button type="primary" size="mini" @click="copy1">复制</button>
					</view>
				</view>
			</view>
			<view>
				<!-- <img src="../../static/icon/code.svg" alt="" class="code-img" /> -->
				<image :src="imgSrc" alt="" class="code-img"></image>
			</view>
			<view class="sub-title">
				<text>扫一扫二维码，加入群聊</text>
			</view>
			<view class="share">
				<view class="share-item" @click="upload">
					<img :src="getResource('/icon/upload.svg')" alt="" class="share-img">
					<text>保存</text>
				</view>
				<view class="share-item" @click="share">
					<img :src="getResource('/icon/share.svg')" alt="" class="share-img">
					<text>分享</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			groupId: null,
			group: {},
			imgSrc: ""
		}
	},
	methods: {
		loadGroupInfo() {
			this.$http({
				url: `/group/findGroupById/${this.groupId}`,
				method: 'GET'
			}).then((group) => {
				group.groupNumber = this.padNumber(group.groupNumber)
				console.log('123', group)
				this.group = group;
				console.log('456', this.group)
			});
		},
		padNumber(number) {
			return number.toString().padStart(6, '0');
		},
		loadGroupCode() {

			this.$http({
				url: `/system/qrcode`,
				method: 'POST',
				data: {
					body: JSON.stringify({
						groupId: this.groupId
					})
				}
			}).then((code) => {
				this.imgSrc = code
			});
		},
		copy1() {
			let text = this.group.groupNumber

			uni.setClipboardData({
				data: text.toString(),
				success: function (res) {
					console.log('复制的信息1：', text);
					uni.showToast({
						title: '复制成功',
					});
				}
			});
		},
		upload() {

		},
		share() {

		},
	},
	computed: {

	},
	onShow() {
		// this.intervalId = setInterval(() => {
		// 	this.loadGroupCode(this.groupId);
		// }, 10000);
	},
	onHide() {
		// clearInterval(this.intervalId);
	},
	onLoad(options) {
		this.groupId = options.id;
		// 查询群聊信息
		this.loadGroupInfo(options.id);
		this.loadGroupCode(options.id);
	}
}
</script>

<style lang="less" scoped>
.user-info {
	width: 100vw;
	height: 70vh;
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;

	.head {
		display: flex;
		align-items: center;

		.avatar-image {
			width: 50px;
			height: 50px;
			border-radius: 5px;
		}

		.right {

			// padding-top: 100rpx;
			text {
				margin-left: 40rpx;
			}

			.num-item {
				display: flex;
				align-items: center;
				color: #aaa;
				font-size: 30rpx;
				margin-top: 20rpx;

				button {
					height: 40rpx;
					line-height: 40rpx;
					margin-left: 20rpx;
					background-color: #048df5;
					color: #fff;
				}
			}
		}
	}

	.code-img {
		width: 550rpx;
		height: 550rpx;
		margin-top: 20rpx;
	}

	.sub-title {
		font-size: 25rpx;
		color: #aaa;
	}

	.share {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		bottom: 0;
		left: 0;

		.share-item {
			display: flex;
			align-items: center;
			flex-direction: column;
			padding: 20rpx;
			width: 50%;

			.share-img {
				width: 65rpx;
				height: 65rpx;
			}

			text {
				margin-top: 20rpx;
			}
		}

	}
}
</style>